﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Process.Entities;
using Process.BLL;
using System.Data;

namespace Business
{
    public partial class Products : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string catelogyID = Request.QueryString["CategoryID"];
                if (catelogyID != null)
                    Session["CatelogyID"] = catelogyID;
                int page = int.Parse("0" + Request.QueryString["page"]);
                if (page == 0) page = 1;
                NapDuLieu(Session["CatelogyID"].ToString(), page, 1, 7);
            }
        }
       
        private void NapDuLieu(string catelogyID, int currPage, int recordperpage, int pagesize)
        {
            DataSet ds = ProductBLL.getListProductByCategoryID(catelogyID, currPage, recordperpage, pagesize);
            DataTable dtbData = ds.Tables[0];
            DataTable dtbPhanTrang = ds.Tables[1];
            if (dtbData.Rows.Count > 0)
            {
                dtl_ListProduct.DataSource = dtbData;
                dtl_ListProduct.DataBind();
                if (dtbPhanTrang.Rows.Count > 0)
                {
                    ltlPhanTrang.Text = dtbPhanTrang.Rows[0]["PhanTrang"] + "";
                }
            }
        }
        protected void ImageButton1_Command(object sender, CommandEventArgs e)
        {
            string productID = e.CommandName;
            CartBLL cart = (CartBLL)Session["cart"];
            if (cart == null)
            {
                cart = new CartBLL();
            }

            //cart.CreateTempCart(productID, 1);
            ProductENT product = ProductBLL.GetProductByID(productID);
            //cart.CreateTempCart(productID, 1, product.ProductName, product.UnitPrice);
            Session.Add("cart", cart);
        }

    }
}